package com.guide.router;

/**
 * super class of sharding strategies
 * @author GuoHongtao [Kingsoft Cloud]
 * @date 2013�?0�?5�?
 * @param <V> type of id
 * @param <T> type of database identifier
 */
public abstract class DBRouter {
	
	public DBRouter(){
		
	}
	
	/**
	 * 
	 * @param shardingId
	 * @param shardCount
	 * @return 索引值，大于等于0，小于shardCount
	 * @date
	 */
	abstract public int getShardingIndex(long shardingId, int shardCount);
	
	/**
	 * 
	 * @param shardingId
	 * @param cellCount
	 * @return table index, 大于等于0，小于cellCount, -1 - single table
	 * @date 
	 */
	abstract public int getTableIndex(long shardingId, int cellCount);
	
	private static DBRouter noShardingRouter = new DBRouter() {
		
		@Override
		public int getTableIndex(long shardingId, int cellCount) {
			return -1;
		}
		
		@Override
		public int getShardingIndex(long shardingId, int shardCount) {
			return 0;
		}
	};

	public static DBRouter getSingletonNoShardingRouter() {
		return noShardingRouter;
	}

}
